﻿Public Class ObjektMultiValue
    Dim Values As ObjektValueSchieber() = {}
    Dim LetztesValues As Integer = 0
    Public Property LetztesValue() As Integer
        Get
            Return LetztesValues
        End Get
        Set(ByVal value As Integer)
            LetztesValues += 1
            If LetztesValues > Values.Length - 1 Then
                LetztesValues = 0
            End If
        End Set
    End Property
    Dim MinValue, MaxValue As Integer
    Public Sub New(ByVal MinValue As Integer, ByVal MaxValue As Integer, ByVal ZahlderValues As Integer, ByVal Position As Point, ByVal Breite As Integer, ByVal ValueAbstand As Integer, ByVal Fixed As PointF, Optional ByVal Handler As ObjektPanel = Nothing)
        Array.Resize(Values, ZahlderValues)
        Dim R As Integer
        Me.MinValue = MinValue
        Me.MaxValue = MaxValue
        Dim Startvalue As Integer = Math.DivRem(MaxValue, ZahlderValues, R)
        For I = 0 To ZahlderValues - 1
            Values(I) = New ObjektValueSchieber("ValueRegler", MinValue, MaxValue, Breite, Position, Startvalue, Fixed, , , "%", Handler)
            Position.Y += ValueAbstand
        Next
        Dim I2 As Integer = 0
        While R > 0
            Values(I2).Value += 1
            I2 += 1
            If I2 > Values.Length - 1 Then
                I2 = 0
            End If
            R -= 1
        End While
    End Sub
    Public Sub MouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
        'Aber wir müssen evtl. Die Values verschieben
        MouseUp(e.X, e.Y)
    End Sub
    Public Sub MouseUp(ByVal X As Integer, ByVal Y As Integer)
        For I = 0 To Values.Length - 1
            Values(I).MouseUp(X, Y)
        Next
    End Sub
    Public Sub MouseDown(ByVal X As Integer, ByVal Y As Integer)
        For I = 0 To Values.Length - 1
            Values(I).MouseDown(X, Y)
        Next
    End Sub
    Public Sub MouseMove(ByVal X As Integer, ByVal Y As Integer)
        For I = 0 To Values.Length - 1
            Dim AltesValue As Integer = Values(I).Value
            Values(I).MouseMove(X, Y)
            ValuesÄndern(AltesValue, I)
        Next
    End Sub
    Public Sub Malen()
        'MyBase.Malen()
        For I = 0 To Values.Length - 1
            Dim AltesValue As Integer = Values(I).Value
            Values(I).Malen()
            ValuesÄndern(AltesValue, I)
        Next
    End Sub
    Private Sub ValuesÄndern(ByVal AltesValue As Integer, ByVal Value As Integer)
        Dim Z As Integer = Values(Value).Value - AltesValue
        Dim Änderung As Integer = -1
        If Z < 0 Then
            Änderung = 1
            Z *= -1
        End If
        For I = 1 To Z
            Dim B As Boolean = False
            While B = False
                If Values(LetztesValue).Value + Änderung < MinValue Or Values(LetztesValue).Value + Änderung > MaxValue Then
                    B = False
                    LetztesValue = 1
                Else
                    Values(LetztesValue).Value = Änderung
                    LetztesValue = 1
                    B = True
                End If
            End While
        Next
    End Sub
    Public Function GetValue(ByVal Value As Integer) As Integer
        Return Values(Value).Value
    End Function
    Public Sub SetValue(ByVal Value As Integer, ByVal Wert As Integer, ByVal AutoComplet As Boolean)
        If AutoComplet = False Then
            Values(Value).SetValue(Wert)
        Else
            Dim Alt As Integer = Values(Value).Value
            Values(Value).SetValue(Wert)
            ValuesÄndern(Alt, Value)
        End If
    End Sub
    Public Sub ChangeWindowSize(ByVal PosChange As System.Drawing.Point)
        For Each Value In Values
            Value.ChangeWindowSize(PosChange)
        Next
    End Sub
End Class
